<template>
	<div class="updatepwd">
		<h1>更改密码</h1>
		<el-form label-width="80px">
			<el-form-item label="旧密码:">
				<el-input v-model="oldpwd"></el-input>
			</el-form-item>
			<el-form-item label="新密码:">
				<el-input v-model="newpwd"></el-input>
			</el-form-item>
			<el-form-item label="新密码:">
				<el-input v-model="newpwd2"></el-input>
			</el-form-item>
		</el-form>
		<el-button @click="doup()">保存</el-button>
	</div>
</template>

<script>
	export default {
		name: 'moblieupdatepwd',
		data() {
			return {
				oldpwd: '',
				newpwd: '',
				newpwd2: '',
				user: {}
			}
		},
		methods: {
			doup() {
				this.user = {
					oldPwd: this.oldpwd,
					newPwd: this.newpwd2
				}
				console.log(this.oldpwd);
				console.log(this.newpwd);
				if (this.newpwd != this.newpwd2) {
					this.$message.error('两次密码不一致');

				} else {
					this.$postkv('/api/user/updatePwd', this.user).then((resp) => {
						console.log(resp.data.data);
						console.log(resp.data.msg);
						if (resp.data.msg == "旧密码输入有误") {
							this.$message.error('重新输入旧密码');
						} else {
							this.$message({
								showClose: true,
								message: '修改成功,请重新登录'
							});
							window.localStorage.clear();
							this.$router.push('/mobile/myhome');
						}


					})
				}
			}
		},
		mounted() {

		}
	}
</script>

<style>
	.updatepwd h1 {
		text-align: center;
	}

	.updatepwd form {
		margin-top: 10%;
		width: 100%;
	}

	.updatepwd input {
		width: 80%;
	}

	.updatepwd button {
		border: none;
		margin-left: 42%;
	}
</style>